﻿using Entity.BaseInfo.DTO.Supplier;
using Entity.BaseInfo.View.Supplier;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 供应商表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class SupplierController : ControllerBase
    {
        /**
         * 供应商业务接口
         */
        private readonly SupplierService _supplierService;

        /**
         * 构造函数注入
         */
        public SupplierController(SupplierService supplierService)
        {
            _supplierService = supplierService;
        }

        /// <summary>
        /// 获取供应商列表
        /// </summary>
        /// <param name="supplierSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(SupplierView), 200)]
        public async Task<IActionResult> GetSupplierList([FromQuery] SupplierSearchDTO supplierSearchDTO)
        {
            var response = await _supplierService.GetSupplierList(supplierSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增供应商
        /// </summary>
        /// <param name="supplierAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddSupplier([FromBody] SupplierAddDTO supplierAddDTO)
        {
            var response = await _supplierService.AddSupplier(supplierAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新供应商
        /// </summary>
        /// <param name="supplierUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutSupplier([FromBody] SupplierUpdateDTO supplierUpdateDTO)
        {
            var response = await _supplierService.PutSupplier(supplierUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除供应商
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteSupplier([FromQuery] string Id)
        {
            var response = await _supplierService.DeleteSupplier(Id);
            return StatusCode(response.Status, response);
        }
    }
}
